/* GUI CONVERTED from bmwuiqa.p (converter v1.76) Sat Mar 29 00:35:47 2003 */
/* bmwuiqa.p - WHERE-USED INQUIRY                                       */
/* Copyright 1986-2003 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.9.1.14 $                                                */
/*V8:ConvertMode=Report                                                 */
/* REVISION: 1.0      LAST EDIT:     06/11/86   BY: EMB                 */
/* REVISION: 2.1      LAST EDIT:     09/02/87   BY: WUG *A94*           */
/* REVISION: 4.0      LAST EDIT:     12/30/87   BY: WUG *A137*          */
/* REVISION: 4.0      LAST EDIT:     04/28/88   BY: EMB                 */
/* REVISION: 5.0      LAST EDIT:     05/03/89   BY: WUG *B098*          */
/* REVISION: 5.0      LAST EDIT:     08/16/90   BY: WUG *D051*          */
/* REVISION: 6.0      LAST EDIT:     01/07/91   BY: bjb *D248*          */
/* REVISION: 7.2      LAST MODIFIED: 11/02/92   BY: pma *G265*          */
/* REVISION: 7.3      LAST MODIFIED: 10/26/93   BY: ais *GG68*          */
/* REVISION: 7.3      LAST MODIFIED: 12/20/93   BY: ais *GH69*          */
/* REVISION: 7.3      LAST MODIFIED: 12/29/93   BY: ais *FL07*          */
/* REVISION: 8.6      LAST MODIFIED: 10/15/97   BY: mur *K124*          */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane     */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan    */
/* REVISION: 9.0      LAST MODIFIED: 07/30/99   BY: *J3J4* Jyoti Thatte  */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane  */
/* REVISION: 9.1      LAST MODIFIED: 07/04/00   BY: *N0F3* Rajinder Kamra    */
/* REVISION: 9.1      LAST MODIFIED: 08/11/00   BY: *N0KK* jyn               */
/* Old ECO marker removed, but no ECO header exists *F0PN*                   */
/* Old ECO marker removed, but no ECO header exists *G345*                   */
/* Revision: 1.9.1.8     BY: Falguni            DATE: 06/28/01  ECO: *M1C6*  */
/* Revision: 1.9.1.10    BY: Subashini Bala     DATE: 01/29/02  ECO: *N18L*  */
/* Revision: 1.9.1.11    BY: Ashish Kapadia     DATE: 06/12/02  ECO: *N1L7*  */
/* Revision: 1.9.1.12    BY: Ashish Maheshwari  DATE: 11/08/02  ECO: *N1Z4*  */
/* Revision: 1.9.1.13    BY: Vinod Nair         DATE: 11/19/02  ECO: *N1ZW*  */
/* $Revision: 1.9.1.14 $   BY: Deepali Kotavadekar DATE: 03/28/03  ECO: *P0PD*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/****************************************************************************/
/*             THIS PROGRAM COMBINES BMWUIQ.P & FMWUIQ.P                    */
/*       BOTH PROGRAMS NAMED THE DETAIL FRAME 'HEADING";  THIS              */
/*       COMBIND PROGRAM USES FRAMES BM & FM.  WHERE THESE FRAME            */
/*       NAMES ARE USED, THE PREVIOUS PROGRAMS USED 'HEADING'               */
/****************************************************************************/

/* DISPLAY TITLE */

/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "2+ "}

/* ********** Begin Translatable Strings Definitions ********* */

&SCOPED-DEFINE bmwuiqa_p_1 "Ph"
/* MaxLen: Comment: */

&SCOPED-DEFINE bmwuiqa_p_2 "Levels"
/* MaxLen: Comment: */

&SCOPED-DEFINE bmwuiqa_p_3 "As Of"
/* MaxLen: Comment: */

&SCOPED-DEFINE bmwuiqa_p_4 "Level"
/* MaxLen: Comment: */

&SCOPED-DEFINE bmwuiqa_p_6 "/no"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define shared variable transtype as character format "x(4)".
define variable comp like ps_comp.
define variable level as integer.
define variable maxlevel as integer format ">>>" label {&bmwuiqa_p_2}.
define variable eff_date as date column-label {&bmwuiqa_p_3}.
define variable parent    like ps_comp.
define variable l_parent1 like ps_comp no-undo.
define variable desc1 like pt_desc1.
define variable um like pt_um.
define variable phantom like mfc_logical format "yes" label {&bmwuiqa_p_1}.
define variable iss_pol like pt_iss_pol format {&bmwuiqa_p_6}.
define variable record as integer extent 100.
define variable lvl as character format "x(7)" label {&bmwuiqa_p_4}.

define variable l_level   as integer initial 0 no-undo.
define variable l_psrecid as recid no-undo.
define variable l_next    like mfc_logical initial yes no-undo.
define variable l_nextptp like mfc_logical initial no  no-undo.
define variable l_phantom as   character      format "x(3)" no-undo.
define variable l_iss_pol as   character      format "x(3)" no-undo.

define buffer ptmstr1 for pt_mstr.
define buffer psmstr  for ps_mstr.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   parent
   desc1
   um
   eff_date
   maxlevel
with frame a width 80 attr-space no-underline THREE-D /*GUI*/.

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

/* INTRODUCED VARIABLE l_parent1 TO BE USED INSTEAD OF VARIABLE parent IN */
/* WEB APPLICATION MODE TO AVOID CONFLICT OF VALUE OF parent IN BOTH THE  */
/* FRAMES                                                                 */
FORM /*GUI*/ 
   l_parent1
   desc1
   um
   eff_date at 60
   maxlevel label "            Levels"
with STREAM-IO /*GUI*/  frame a1 width 90 attr-space no-underline.

/* SET EXTERNAL LABELS */
setFrameLabels(frame a1:handle).

eff_date = today.

/* SET PARENT TO GLOBAL PART NUMBER */
parent = global_part.

{wbrp02.i}

if c-application-mode = 'WEB'
then
   assign
      l_parent1   = global_part
      desc1:label = ""
      um:label    = "".

repeat:

   if c-application-mode <> 'web'
   then
      update
         parent
         eff_date
         maxlevel
      with frame a editing:

         if frame-field = "parent"
         then do:
            /* FIND NEXT/PREVIOUS RECORD */
            {mfnp.i ps_mstr parent ps_comp parent ps_comp ps_comp}

            if recno <> ?
            then do:
               assign
        	      parent:screen-value  = ps_comp
                  parent  = ps_comp	
                  desc1   = "".

               find pt_mstr
                  where pt_part = parent
                  no-lock
                  no-error.
               if available pt_mstr
               then
                  desc1 = pt_desc1.
               else do:
                  find bom_mstr
                     where bom_parent = parent
                     no-lock
                     no-error.
                  if available bom_mstr
                  then
                     desc1 = bom_desc.
               end.
               display parent desc1 with frame a.
               recno = ?.
            end.
         end.
         else do:
            status input.
            readkey.
            apply lastkey.
         end.
      end.

      {wbrp06.i
         &command = update
         &fields = "l_parent1 eff_date maxlevel"
         &frm = "a1"}

      if c-application-mode = 'web'
      then
         parent = l_parent1.

      if (c-application-mode <> 'web') or
         (c-application-mode = 'web' and
         (c-web-request begins 'data'))
      then do:
         assign
            desc1 = ""
            um    = ""
            parent
            l_parent1.

            find pt_mstr
               use-index pt_part
               where pt_part = parent
               no-lock
               no-error.
            if not available pt_mstr
            then do:
               find bom_mstr
                  where bom_parent = parent
                  no-lock
                  no-error.
               if not available bom_mstr
               then do:
                  hide message no-pause.
                  {pxmsg.i &MSGNUM=17 &ERRORLEVEL=3}
                  display desc1 um with frame a.
                  if c-application-mode = 'web'
                  then
                     return.
                  undo, retry.
               end.
               assign
                  um        = bom_batch_um
                  desc1     = bom_desc
                  parent    = bom_parent
                  l_parent1 = parent.
            end.
            else
               assign
                  desc1     = pt_desc1
                  um        = pt_um
                  parent    = pt_part
                  l_parent1 = parent.

            display parent desc1 um with frame a.

            hide frame bm.
            hide frame fm.

         end.

        /* OUTPUT DESTINATION SELECTION */
        {gpselout.i
           &printType = "terminal"
           &printWidth = 132
           &pagedFlag = " "
           &stream = " "
           &appendToFile = " "
           &streamedOutputToTerminal = " "
           &withBatchOption = "no"
           &displayStatementType = 1
           &withCancelMessage = "yes"
           &pageBottomMargin = 6
           &withEmail = "yes"
           &withWinprint = "yes"
           &defineVariables = "yes"}

        assign
           l_next    = yes
           l_nextptp = no
           level     = 0
           comp      = parent
           maxlevel  = min(maxlevel,99)
           level     = 1.

        find first ps_mstr
           use-index ps_comp
           where ps_comp = comp
           no-lock
           no-error.

        repeat:

           
/*GUI*/ {mfguichk.i } /*Replace mfrpchk*/


           /*DETAIL FORM (BM)*/
           FORM /*GUI*/ 
              lvl
              ps_par
              desc1
              ps_qty_per
              um
              phantom
              ps_ps_code
              iss_pol
           with STREAM-IO /*GUI*/  frame bm width 132 no-attr-space.

           /* SET EXTERNAL LABELS */
           setFrameLabels(frame bm:handle).

           /*DETAIL FORM (FM)*/
           FORM /*GUI*/ 
              lvl
              ps_par
              desc1
              ps_qty_per_b
              ps_qty_type
              um
              phantom
              ps_ps_code
           with STREAM-IO /*GUI*/  frame fm width 132 no-attr-space.

           /* SET EXTERNAL LABELS */
           setFrameLabels(frame fm:handle).

           if not available ps_mstr
           then do:
              repeat:
                 level = level - 1.
                 if level < 1
                 then
                    leave.
                 find ps_mstr
                    where recid(ps_mstr) = record[level]
                    no-lock
                    no-error.
                 comp = ps_comp.
                 find next ps_mstr
                    use-index ps_comp
                    where ps_comp = comp
                    no-lock
                    no-error.
                 if available ps_mstr
                 then
                    leave.
              end.
           end.
           if level < 1
           then
              leave.

           if eff_date = ? or (eff_date <> ? and
             (ps_start = ? or ps_start <= eff_date) and
             (ps_end = ? or eff_date <= ps_end))
           then do:

              assign
                 desc1 = ""
                 um    = ""
                 iss_pol = no
                 phantom = no.

              find pt_mstr
                 where pt_part = ps_par
                 no-lock
                 no-error.
              if available pt_mstr
              then
                 assign
                    desc1   = pt_desc1
                    um      = pt_um
                    iss_pol = pt_iss_pol
                    phantom = pt_phantom.
              else do:
                 find bom_mstr
                    where bom_parent = ps_par
                    no-lock
                    no-error.
                 if available bom_mstr
                 then
                    assign
                       um    = bom_batch_um
                       desc1 = bom_desc.
              end.

              if phantom
              then
                 l_phantom  = getTermLabel("Yes",3).
              else
                 l_phantom =  getTermLabel("No",3).

              if iss_pol
              then
                 l_iss_pol  = getTermLabel("Yes",3).
              else
                 l_iss_pol =  getTermLabel("No",3).

              assign
                 record[level] = recid(ps_mstr)
                 lvl           = "......."
                 lvl           = substring(lvl,1,min(level - 1,6))
                                    + string(level).

              if length(lvl) > 7
              then
                 lvl = substring(lvl,length(lvl) - 6,7).

              if transtype = "BM"
              then do with frame bm down:
                 if frame-line = frame-down and frame-down <> 0
                    and available pt_mstr and pt_desc2 > ""
                 then
                    down 1 with frame bm.

                 display
                    lvl
                    ps_par
                    desc1
                    ps_qty_per
                    um
                    l_phantom @ phantom
                    ps_ps_code
                    l_iss_pol @ iss_pol
                 with frame bm STREAM-IO /*GUI*/ .

                 if available bom_mstr and not available pt_mstr
                 then
                    display
                       getTermLabel("BOM",3) format "x(3)" @ phantom
                    with frame bm STREAM-IO /*GUI*/ .
                 if available pt_mstr and pt_desc2 > ""
                    then do with frame bm:
                       down 1.
                       display pt_desc2 @ desc1 WITH STREAM-IO /*GUI*/ .
                    end.
                 end.
                 else do with frame fm down:
                 if frame-line = frame-down and frame-down <> 0
                    and available pt_mstr and pt_desc2 > ""
                 then
                    down 1 with frame fm.

                 display
                    lvl
                    ps_par
                    desc1
                    ps_qty_per_b
                    ps_qty_type
                    um
                    l_phantom @ phantom
                    ps_ps_code
                 with frame fm STREAM-IO /*GUI*/ .

                 if available bom_mstr and not available pt_mstr
                 then
                    display
                       getTermLabel("BOM",3) format "x(3)" @ phantom
                    with frame bm STREAM-IO /*GUI*/ .
                    if available pt_mstr and pt_desc2 > ""
                    then do with frame fm:
                       down 1.
                       display pt_desc2 @ desc1 WITH STREAM-IO /*GUI*/ .
                    end.
                 end.

                 if level < maxlevel or maxlevel = 0
                 then do:
                    assign
                       comp = ps_par
                       level = level + 1.
                    find first ps_mstr
                       use-index ps_comp
                       where ps_comp = comp
                       no-lock
                       no-error.
                    if not available ps_mstr
                    then
                       run p-getbom.
                 end.
                 else do:
                    find next ps_mstr
                       use-index ps_comp
                       where ps_comp = comp
                       no-lock
                       no-error.
                    if not available ps_mstr
                    then
                       run p-getbom.
                 end.
              end.
              else
                 find next ps_mstr
                    use-index ps_comp
                    where ps_comp = comp
                    no-lock
                    no-error.
                 end.
              {mfreset.i}
/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/

              {pxmsg.i &MSGNUM=8 &ERRORLEVEL=1}
           end.
           global_part = parent.

           if c-application-mode = 'web'
           then
              global_part = l_parent1.

           {wbrp04.i &frame-spec = a1}

/* IF THE PRODUCT STRUCTURE RECORD IS NOT AVAILABLE THEN THIS  */
/* PROCEDURE EXPLODES FURTHER USING THE PTP_DET AND PT-MSTR    */
/* BY VERIFYING IF THE COMPONENT EXISTS AS A BOM CODE FOR ANY  */
/* OTHER ITEMS.                                                */
PROCEDURE p-getbom:
   if l_next
   then do:
      for first ptp_det
         fields(ptp_bom_code ptp_part)
         where ptp_det.ptp_bom_code = comp
         no-lock :
      end. /* FOR FIRST PTP_DET */
      if available ptp_det
      then do:
         l_nextptp = yes.
         for first ptmstr1
            fields(pt_bom_code pt_desc1 pt_desc2 pt_iss_pol pt_part pt_phantom)
            where  ptmstr1.pt_part = ptp_part
            no-lock :
         end. /* FOR FIRST PTMSTR1 */
      end. /* IF AVAILABLE PTP_DET */
      else
         for first ptmstr1
            fields(pt_bom_code pt_desc1 pt_desc2 pt_iss_pol pt_part pt_phantom)
            where ptmstr1.pt_bom_code = comp
            no-lock :
      end. /* FOR FIRST PTMSTR1 */

      for first psmstr
         fields(ps_comp ps_end ps_lt_off ps_par ps_ps_code ps_qty_per
                ps_qty_per_b ps_qty_type ps_ref ps_scrp_pct ps_start)
         where psmstr.ps_par = comp
         no-lock :
      end. /* FOR FIRST PSMSTR */
      if available psmstr
      then
         assign
            l_psrecid = recid(psmstr)
            l_level = level.
      end. /* L_NEXT = YES */
      else do:
         for first psmstr
            fields(ps_comp ps_end ps_lt_off ps_par ps_ps_code ps_qty_per
                   ps_qty_per_b ps_qty_type ps_ref ps_scrp_pct ps_start)
            where recid(psmstr) = l_psrecid
            no-lock :
      end. /* FOR FIRST PSMSTR */
      find next ptp_det
         where ptp_det.ptp_bom_code = psmstr.ps_par
         no-lock
         no-error.
      if available ptp_det
      then do:
         for first ptmstr1
            fields(pt_bom_code pt_desc1 pt_desc2 pt_iss_pol pt_part pt_phantom)
            where ptmstr1.pt_part = ptp_part
            no-lock :
         end. /* FOR FIRST PTMSTR1 */
      end. /* IF AVAIL PTP_DET */
      else do:
         if l_nextptp = yes
         then do:
            for first ptmstr1
               fields(pt_bom_code pt_desc1 pt_desc2 pt_iss_pol pt_part
                      pt_phantom)
               where ptmstr1.pt_bom_code = psmstr.ps_par
               no-lock :
            end. /* FOR FIRST PTMSTR1 */
            l_nextptp = no.
         end. /* IF L_NEXTPTP = YES */
         else do:
            find next ptmstr1
               where ptmstr1.pt_bom_code = psmstr.ps_par
                 and not(can-find (first ptp_det
                                      where ptp_part = pt_part
                                        and ptp_bom_code = ptmstr1.pt_bom_code))
               no-lock
               no-error.
            l_nextptp = no.
         end. /* ELSE IF L_NEXTPTP = NO */
      end. /* IF NOT AVAILABLE PTP_DET */
      if available ptmstr1
      then
         level = l_level.
   end. /* ELSE IF L_NEXT = NO */

   bomloop1:
   do while available ptmstr1:
      l_next = no.
      for first ps_mstr
         fields(ps_comp ps_end ps_lt_off ps_par ps_ps_code ps_qty_per
                ps_qty_per_b ps_qty_type ps_ref ps_scrp_pct ps_start)
         where ps_mstr.ps_comp = ptmstr1.pt_part
         use-index ps_comp
         no-lock :
      end. /* FOR FIRST PS_MSTR */
      if available ps_mstr
      then do:
         comp = ptmstr1.pt_part.
         leave bomloop1.
      end. /* if available ps_mstr */
      else if not available ps_mstr
      then do:
         find next ptp_det
            where ptp_det.ptp_bom_code = comp
            no-lock
            no-error.
         if available ptp_det
         then do:
            find next ptmstr1
               where ptmstr1.pt_part = ptp_part
               no-lock
               no-error.
         end. /* IF AVAIL PTP_DET */
         else  do:
            find next ptmstr1
               where ptmstr1.pt_bom_code = comp
               no-lock
               no-error.
            if not available ptmstr1
            then do:
               for first psmstr
                  fields(ps_comp ps_end ps_lt_off ps_par ps_ps_code ps_qty_per
                         ps_qty_per_b ps_qty_type ps_ref ps_scrp_pct ps_start)
                  where recid(psmstr) = l_psrecid
                  no-lock :
               end. /* FOR FIRST PSMSTR */
               find next ptmstr1
                  where ptmstr1.pt_bom_code = psmstr.ps_par
                    and not(can-find (first ptp_det
                                         where ptp_part = pt_part and
                                         ptp_bom_code = ptmstr1.pt_bom_code))
                  no-lock
                  no-error.
            end. /* IF NOT AVAILABLE PTMSTR1 */
         end. /* ELSE DO */
      end. /* IF NOT AVAIL PS_MSTR */
   end. /* IF AVAILABLE PTMSTR BOMLOOP1 */
END PROCEDURE. /* P-GETBOM */
